<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BScreenCreateServiceSummary
 *
 * @author ID59C
 */
class BScreenCreateServiceSummary extends BUIScreen {

    //put your code here
    public $title = "Create Service Summary";

    public function render($data = null) {

        $listLayout = new BUIViewLayout(BUIViewLayout::LIST_LAYOUT);

        //add page title
        $listLayout->addViewItem('pagetitle', array('pageTitle' => $this->title));

        //add screenActions with subtitle
        $uiNode = $this->getUINode();
        $screenActions = $uiNode->getScreenActionGroup('CreateServiceActions');

        foreach ($screenActions as $screenAction) {
            $subTitle = $screenAction->getScreen() . '\' actions:' . $screenAction->getStatus();
            $listLayout->addViewItem('subtitle', array('subTitle' => $subTitle));

            $detail = $this->getDetailViewData($screenAction);
            $listLayout->addViewItem('detailview', array('detailViewData' => $detail['data'],
                'detailViewAttributes' => $detail['attributes']));
        } 

        //add buttons   
        /*
          $viewData = array();
          $viewData['buttons'] = array(
          array('label' => 'Confirm', 'url' => '#'),
          array('label' => 'Cancel', 'url' => '#')
          );

          $listLayout->addViewItem('inline-buttons', $viewData);
         * 
         */

        //add buttons into inline layout view

        $inLineLayout = new BUIViewLayout(BUIViewLayout::INLINE_LAYOUT);
        $inLineLayout->addViewItem('bootstrap-button', array('button'=>array('label' => 'Confirm', 'url' => '#')));
        $inLineLayout->addViewItem('bootstrap-button', array('button'=>array('label' => 'Cancel', 'url' => '#')));

        $listLayout->addViewItem($inLineLayout->getLayoutView(), $inLineLayout->getLayoutData());
        
        $this->renderView($listLayout->getLayoutView(), $listLayout->getLayoutData());
    }

    protected function getDetailViewData($screenAction) {
        $result = array();
        $detailAttributes = array();
        $datailData = array();
        $inputElements = $screenAction->getInputElements();

        foreach ($inputElements as $element) {
            $name = $element['name'];
            $value = $element['displayValue'] == null ? $element['value'] : $element['displayValue'];
            array_push($detailAttributes, array('name' => $element['name'], 'label' => $element['name']));
            $datailData[$name] = $value;
        }
        $result['data'] = $datailData;
        $result['attributes'] = $detailAttributes;
        return $result;
    }

}

?>
